<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <style>
        div {
            width: 500px;
            margin: 30px auto;
            text-align: center;
        }

        span {
            display: inline-block;
            width: 50px;
        }

        img {
            vertical-align: middle;
            width: 30px;
        }
    </style>


</head>

<body>

    <div>
        <span id="capcha">5位验证码</span>
        <img src="../素材/images/arrow_03.png" id="change_capcha" alt="">
    </div>

    <!-- abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -->
    <script>
        let capcha = document.getElementById('capcha');
        let change_capcha = document.getElementById('change_capcha');
        let codeStr = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        let length = 5;

        change_capcha.style.cursor = 'pointer';
        capcha.style.cursor = 'pointer';

        function getrandownum(n, m) {
            if (n > m) {
                let tmp = n;
                n = m;
                m = tmp;
            }
            return parseInt(Math.random() * (m - n + 1) + n);
        }

        function getCode() {
            let str = '';
            for (let i = 0; i < length; i++) {
                let index = getrandownum(0, 61);
                str += codeStr.charAt(index);
            }
            //alert(str);
            capcha.innerHTML = str;
        }

        getCode();

        change_capcha.onclick = function () {
            getCode();
        }

        capcha.onclick = function () {
            getCode();
        }
    </script>

</body>

</html>